package com.youlu.campus.admin.community.controller;

import com.youlu.campus.admin.annotation.RequestActivityAuth;
import com.youlu.campus.common.base.RestResult;
import com.youlu.campus.common.base.RestResultBuilder;
import com.youlu.campus.service.activity.UserActivityTaskRankingAttachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Slf4j
@RestController
public class UserActivityTaskRankingAttachController {
    @Autowired
    private UserActivityTaskRankingAttachService userActivityTaskRankingAttachService;

    /**
     * 导入贡献值
     *
     * @param file
     * @param activityId
     * @param comments
     * @return
     */
    @PostMapping("/task/q/import")
    @RequestActivityAuth(activityId = "#activityId")
    public RestResult shipImport(@RequestParam("file") MultipartFile file,
                                 @RequestParam("activityId") String activityId,
                                 @RequestParam("comments") String comments) {
        try {
            String fileName = file.getOriginalFilename();
            log.info(":>>> 批量导入贡献值文件:{}", fileName);
            Map<String, Object> res = userActivityTaskRankingAttachService.dataImport(file.getBytes(), fileName, activityId, comments);
            return RestResultBuilder.builder().success(res).build();
        } catch (Exception e) {
            log.info(":>>> 批量导入贡献值文件错误:{}", e);
            return RestResultBuilder.builder().failure().build();
        }
    }
}
